package cn.northsea.controller;

import cn.northsea.pojo.Dept;

import cn.northsea.pojo.User;
import cn.northsea.service.DeptService;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/dept")
public class DeptController {
    @Autowired
    private DeptService deptService;

    @RequestMapping("/toAllocationDept")
    public String toAllocationDept(Integer pageNum, Integer userId, Model model) {
        List<Dept> deptList = deptService.findAll();
        User user = deptService.findUserById(userId);

        model.addAttribute("user", user);
        model.addAttribute("deptList", deptList);
        model.addAttribute("pageNum", pageNum);
        model.addAttribute("userId", userId);
        return "allocationDept";
    }

    @RequestMapping("/allocationDept")
    public String allocationDept(Integer pageNum, Integer userId, Integer deptId, Model model) {
        deptService.allocationDept(userId, deptId);
        model.addAttribute("pageNum", pageNum);
        return "redirect:/user/findAll.do";
    }
}
